//
//  MyfileViewController.m
//  HuateVideo
//
//  Created by Tiger on 12-9-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "MyfileViewController.h"
#import "LocationViewController.h"

@interface MyfileViewController ()

@end

@implementation MyfileViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
        
        [[NSNotificationCenter defaultCenter] addObserver: self
                                                 selector: @selector(toVideoList)
                                                     name: TO_MY_VIDEOS_NOTIFICATION
                                                   object: nil ];
        
        [[NSNotificationCenter defaultCenter] addObserver: self
                                                 selector: @selector(toImageList)
                                                     name: TO_MY_IMAGES_NOTIFICATION
                                                   object: nil ];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    self.view.backgroundColor = TOOLBAR_TINTCOLOR;
    
    items = [[NSMutableArray alloc]initWithObjects:LS(@"我的视频"),LS(@"我的图片"), nil];
    itemsImage = [[NSMutableArray alloc]initWithObjects:@"pindao.png",@"my_image.png", nil];
    
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 367)];
    table.delegate = self;
    table.dataSource = self;
    table.backgroundColor = [UIColor clearColor];
    table.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return [items count];
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	static NSString* ListIdentifier = @"ListIdentifier";
	UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:ListIdentifier];
	
	if (cell == nil)
	{
		cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ListIdentifier] autorelease];
		//cell.selectionStyle = UITableViewCellSelectionStyleNone;  //去掉选中时的颜色
        UIImageView *line = [[UIImageView alloc]initWithFrame:CGRectMake(0, 49, 320, 2)];
        line.image = [UIImage imageNamed:@"fengexian.png"];
        [cell.contentView addSubview:line];
        [line release];
	}
    
    cell.textLabel.text=[items objectAtIndex:indexPath.row];
    cell.imageView.image=[UIImage imageNamed:[itemsImage objectAtIndex:indexPath.row]];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.textLabel.font = [UIFont systemFontOfSize:16.0];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    LocationViewController *locationViewController = [[LocationViewController alloc]init];
    locationViewController.title = LS([items objectAtIndex:indexPath.row]);
    [self.navigationController pushViewController:locationViewController animated:YES];
    [locationViewController release];
}

- (void)toVideoList
{
    [self.navigationController popToRootViewControllerAnimated:NO];
    
    LocationViewController *locationViewController = [[LocationViewController alloc]init];
    locationViewController.title = LS([items objectAtIndex:0]);
    [self.navigationController pushViewController:locationViewController animated:YES];
    [locationViewController release];
}

- (void)toImageList
{
    [self.navigationController popToRootViewControllerAnimated:NO];
    
    LocationViewController *locationViewController = [[LocationViewController alloc]init];
    locationViewController.title = LS([items objectAtIndex:1]);
    [self.navigationController pushViewController:locationViewController animated:YES];
    [locationViewController release];
}

@end
